package trading.ctm.yunjing.view

import android.content.Context
import android.content.Intent
import android.support.v4.content.LocalBroadcastManager
import android.util.AttributeSet
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import cc.vv.lkbasecomponent.util.LKSPUtil
import kotlinx.android.synthetic.main.view_home_information.view.*
import trading.ctm.yunjing.R

class HomeInformationView : LinearLayout {

    constructor(context: Context) : super(context) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        initView()
    }

    fun initView() {
        val view = View.inflate(context, R.layout.view_home_information, null)
        val tv_vhi_information_check_more = view.findViewById<TextView>(R.id.tv_vhi_information_check_more)
        tv_vhi_information_check_more.setOnClickListener {
            val intent = Intent("fragment")
            intent.putExtra("fragment_key", 1)
            LKSPUtil.getInstance().put("isTableHost", 0)
            LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
        }
        this.addView(view)
    }

    fun initData(mData: List<String>){
        clearLinView()

        for(i in 0 until mData.size){
            val view = View.inflate(context, R.layout.view_home_information_item, null)
            val tv_hf_information_item_title = view.findViewById<TextView>(R.id.tv_hf_information_item_title)
            val tv_hf_information_item_lable = view.findViewById<TextView>(R.id.tv_hf_information_item_lable)
            val tv_hf_information_item_time = view.findViewById<TextView>(R.id.tv_hf_information_item_time)
            val tv_hf_information_item_read_number = view.findViewById<TextView>(R.id.tv_hf_information_item_read_number)
            val iv_hf_information_item_icon = view.findViewById<ImageView>(R.id.iv_hf_information_item_icon)
            val view_hf_information_item_line = view.findViewById<View>(R.id.view_hf_information_item_line)
            if(i == mData.size - 1){
                view_hf_information_item_line.visibility = View.INVISIBLE
            }else{
                view_hf_information_item_line.visibility = View.VISIBLE
            }
            view.setOnClickListener {
            }
            ll_vhi_information_list.addView(view)
        }

    }

    private fun clearLinView(){
        ll_vhi_information_list.removeAllViews()
    }
}